home *** CD-ROM | disk | FTP | other *** search
- Path: infoserv.rug.ac.be!asterix
- From: ward.debacker@rug.ac.be (Ward De Backer)
- Newsgroups: comp.lang.c++
- Subject: Visual C++ 4.0 DLL's for Win95 and Visual Basic 4.0
- Date: Tue, 06 Feb 96 20:08:42 GMT
- Organization: JLG AUTOMATION
- Message-ID: <4f7ncl$998@infoserv.rug.ac.be>
- NNTP-Posting-Host: asterix.iic.rug.ac.be
- X-Newsreader: News Xpress Version 1.0 Beta #4
-
- When I develop applications for Windows, I normally use Visual Basic for the
- interface stuff and a DLL written with Visual C++ for the underlying
- algorithms. I have always developed applications for Windows 3.11.
-
- Lastly, I tested the new Visual C++ 4.0 compiler for Windows 95. I wrote a
- 32bit DLL with a simple testfunction in it. On the other side, I wrote a small
- program in Visual Basic that calls this subroutine. The First major difference
- I found was that the basic types of Visual Basic and Visual C++ are no longer
- compatible (i.e. consistent) because an "Integer" in VB is 16 bit wide and a
- standard int in VC++ is 32 bit wide in win95 (unless you declare it as int16).
- But this was not the major problem. When I tried to test my function by
- running my VB program, I couldn't get it to work by no means. Visual Basic
- either didn't find my DLL function or issued a "bad calling convention"
- message. Finally, I inspected my DLL executable with the dumpbin utility. To
- my surprise, I saw a totally different way of naming exported functions.
- Microsoft now uses so called "decorated names" for exported functions. This
- means that a function name is appended with a "@" and the number of bytes on
- the stack the function parameters occupy.
-
- So far, so good. But the problem now is that Visual Basic doesn't recognise
- these decorated names in your DLL. As a consequence, you have to declare all
- the DLL functions with a decorated alias.
-
- To show clearly what's going on, I present an example here:
-
- In Windows 3.11, you wrote in Visual Basic:
-
- Declare Function Test Lib "test.dll" (Byval i As Integer) As Integer
-
- In Visual C++, the declaration could have been this:
-
- extern "C" int FAR PASCAL _export Test(int i)
- {
- ...
- }
-
- Now, in Windows 95, Visual Basic 4.0: (only long variables are now type
- compatible)
-
- Declare Function Test Lib "test.dll" Alias "_Test@4" (Byval l As Long) As Long
-
- In Visual C++ 4.0, the declaration is this:
-
- extern "C" __declspec( dllexport ) long pascal Test(long l)
- {
- ...
- }
-
- Remark the differences:
-
- - FAR disappeared (of course because segmentation is no longer needed)
- - _export is replaced by __declspec (as specified in the Microsoft
- documentation)
- - pascal remians necessary because of the use in Windows of the pascal calling
- convention.
-
- I tested this alos with Excel 7.0 on Windows 95 (in VBA): same results.
-
- My question is: is it not possible to get rid of those funny decorated names ?
- (are there possibilities to circumvent this limitation).
- Or am I doing things completely wrong ???
-
- Is there anyone who has had the same experience ?
-
-
-
- Ward De Backer - JLG AUTOMATION
- Technologiepark Zwijnaarde, 3
- B-9820 ZWIJNAARDE - BELGIUM
-
- E-mail: ward.debacker@rug.ac.be
- FTP-server: asterix.iic.rug.ac.be
- anonymous login possible
-